<template>
<el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dept">
        <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
            <el-form-item>
                <el-input v-model="dataForm.title" placeholder="标题/内容" clearable></el-input>
            </el-form-item>
            <el-form-item>
                <el-select v-model="dataForm.state" placeholder="请选择状态" clearable>
                    <el-option label="待审核" :value="2">
                    </el-option>
                    <el-option label="审核通过" :value="1">
                    </el-option>
                    <el-option label="审核失败" :value="0">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-select v-model="dataForm.type" placeholder="请选择类型" clearable>
                    <el-option label="住宿" :value="2">
                    </el-option>
                    <el-option label="美食" :value="1">
                    </el-option>
                    <el-option label="景点" :value="0">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button @click="getDataList()">{{ $t('query') }}</el-button>
            </el-form-item>
            <el-form-item v-if="$store.state.user.superAdmin==1">
                <el-button type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
            </el-form-item>
        </el-form>
        <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle" style="width: 100%">
            <el-table-column type="selection" align="center" width="50"></el-table-column>
            <el-table-column prop="title" label="标题" min-width="150" align="center"></el-table-column>
            <el-table-column prop="type" label="类型" :show-overflow-tooltip="true" align="center" min-width="120">
                <template slot-scope="scope">
                    {{scope.row.type==0?'景点':scope.row.type==1?'美食':scope.row.type==2?'住宿':''}}
                </template>
            </el-table-column>
            <el-table-column prop="releaseTime" label="发布时间" align="center" min-width="120px"></el-table-column>
            <el-table-column prop="likeNum" label="点赞数量" align="center"></el-table-column>
            <el-table-column prop="state" label="审核状态" align="center" width="140px">
                <template slot-scope="scope">
                    <el-button :type="scope.row.state!=1?'info':'success'" size="mini"> {{scope.row.state==0?'审核失败':scope.row.state==2?'待审核':'审核成功'}}</el-button>
                </template>
            </el-table-column>
            <el-table-column :label="$t('handle')" fixed="right" align="center" width="150">
                <template slot-scope="scope">
                    <el-button type="text" size="small" @click="lookDetail(scope.row.id)">详情</el-button>
                    <el-button type="text" size="small" v-if="scope.row.publisherId==$store.state.user.id" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
                    <el-button v-if="$store.state.user.superAdmin==1&&scope.row.state==2&&scope.row.publisherId!=$store.state.user.id" type="text" size="small" @click="checkData(scope.row.id)">审核</el-button>
                    <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
        </el-pagination>
        <!-- 详情 -->
        <look-detail v-if="lookDetailVisible" ref="lookDetail"></look-detail>
        <!-- 弹窗, 新增 / 修改 -->
        <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" publisherType=1 @refreshDataList="getDataList"></add-or-update>
        <!-- 审核 -->
        <el-dialog title="审核" :visible.sync="dialogFormVisible" width="30%">
            <el-form :model="check">
                <el-form-item label="审核结果" label-width="120px">
                    <el-select v-model="check.state" placeholder="请选择审核结果" clearable style="width:100%">
                        <el-option label="通过" :value="1"></el-option>
                        <el-option label="不通过" :value="0"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="confirmCheck()">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import lookDetail from "./list-add-or-update2";
import AddOrUpdate from "./add-or-update";
export default {
    mixins: [mixinViewModule],
    data() {
        return {
            mixinViewModuleOptions: {
                getDataListURL: "/scenic/tripintrodution/page",
                deleteURL: "/scenic/tripintrodution",
                getDataListIsPage: true,
                deleteIsBatch: true
            },
            dialogFormVisible: false,
            check: {
                state: '',
                id: '',
            },
            dataForm: {
                publisherType: 6,
                type: '',
                state: '',
                title: '',
            },
        };
    },
    components: {
        AddOrUpdate,
        lookDetail
    },
    methods: {
        checkData(id) {
            this.dialogFormVisible = true;
            this.check.id = id;
        },
        confirmCheck() {
            this.$http
                .put("/scenic/tripintrodution/Approved", this.check)
                .then((res) => {
                    if (res.data.code !== 0) {
                        return this.$message.error(res.data.msg);
                    }
                    this.dialogFormVisible = false;
                    this.$message({
                        message: '操作成功',
                        type: "success",
                        duration: 500,
                        onClose: () => {
                            this.getDataList();
                        },
                    });
                });
        },
    }
};
</script>

<style scoped>
.p {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical
}
</style>
